import axios from 'axios';




export default (config, method = 'POST') => {
  const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API,
    timeout: 15000,
    method
  });
  service.interceptors.request.use( config => {
      config.headers = {
        'token': getCookie('token')
      }
      // config.headers.token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNjAiLCJwYXNzd29yZCI6ImhlZmlMN3pBVFZZcE0xaHgxY29XdVdjdVJnRSIsImlkIjoxNjAsImV4cCI6MTYzODMzNzczMSwiaWF0IjoxNjIyNzg1NzMxLCJqdGkiOiJjM2YyZjE4Zi1mYmFiLTRmMGEtOTc1Yy05YTkyYWQ1NzdjNWUiLCJ1c2VybmFtZSI6IueOi-mVv-mdkiJ9.MKKcjBW94kwgya-aUu-z5Cy5QqqYF_mMi15k-9yHoYk'
      // config.headers.token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxNTEiLCJwYXNzd29yZCI6Il8tdDF3RE8xOE0xQWFqLWN2c0x2ZHRWZ09nQSIsImlkIjoxNTEsImV4cCI6MTYzNzkxNDk2NCwiaWF0IjoxNjIyMzYyOTY0LCJqdGkiOiIzYmNmMjcxMi0zNzJkLTRiM2EtYmJjZC02N2UxYWY0MTFmZTYiLCJ1c2VybmFtZSI6IumSseW7uuWujyJ9.FqzwR5Qg5fP0u5LyYKsNkRZ_arIxAGj691rfBZZtiBE'
      // config.headers.token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI3NDgiLCJwYXNzd29yZCI6InZ1cWJ1dUlZdlIyZU83X1E1NmZSYWlSRl9ycyIsImlkIjo3NDgsImV4cCI6MTYzNzU1MTA0OCwiaWF0IjoxNjIxOTk5MDQ4LCJqdGkiOiI2MjRjNjcyNi1kNzdhLTQ3YWItOWMxYy0zMGVjZmU5NTFjMDQiLCJ1c2VybmFtZSI6IuiRo-mdmemdmSJ9.GRhtDEipioKUvkNaG9qYpIWGhim43N3j1NIKMw_sLRE'
      // config.headers = {
      //   'token':'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI3NDgiLCJwYXNzd29yZCI6InZ1cWJ1dUlZdlIyZU83X1E1NmZSYWlSRl9ycyIsImlkIjo3NDgsImV4cCI6MTYzNjc4MjUwMiwiaWF0IjoxNjIxMjMwNTAyLCJqdGkiOiJjMWYwYjFhMy02OTM2LTQyODctODk2Ni1hYjM0MzM5NzRkYmYiLCJ1c2VybmFtZSI6IuiRo-mdmemdmSJ9.L49wE8rA1rAMFAvwanvcmuS0x8JoGZUL4QX-MWTh1xA'
      // }
      return config;
    },
    error => {
      return Promise.reject(error)
    }
  );

  service.interceptors.response.use((res) => {
      if (res.status == 200) {
        return res.data
      } else {
        return Promise.reject()
      }
    },
    error => {
      return Promise.reject(error)
    });
  return service(config)
}
